﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using XnaCanvas;
using matrix = Microsoft.Xna.Framework.Matrix;
using math = Microsoft.Xna.Framework.MathHelper;
using Microsoft.Xna.Framework;

namespace Test.Scenes {
    public partial class XnaBase2DTest2 : UserControl {
        public XnaBase2DTest2() {
            InitializeComponent();
        }

        XObj3 xo,xo2;
        XSence xs;

        private void UserControl_Loaded(object sender, RoutedEventArgs e) {
            this.xcanvas.Trigger.FrameRefresh += Trigger_FrameRefresh;
            //this.xcanvas.Trigger.MouseEnterState += Trigger_MouseEnterState;
            xo = new XObj3();
            xo2 = new XObj3();
            xs = xcanvas.Children[xcanvas.Trigger.Csn];
            //xcanvas.Trigger.Rs.CullMode = Microsoft.Xna.Framework.Graphics.CullMode.None;
            xs.Add("aaa", xo);
            //xs.Add("bbb",xo2);
            xo.SetColor(50, 30, 100, 200);
            //xo2.SetColor(150, 30, 100, 166);
            //xo.effect.EnableDefaultLighting();
            //xo.effect.PreferPerPixelLighting = true;
            //xo2.effect.EnableDefaultLighting();
            //xo2.effect.PreferPerPixelLighting = true;
            //xo2.World *= matrix.CreateRotationX(2.3f);
            xo.LoadParallelPolyhedronPrimitive();

            //
            //xo.LoadParallelPolyhedronPrimitive(y => 1, h => 1, new[] { 0.0d, math.Pi / 2, math.Pi, 3 * math.Pi / 2 }, new[] { 0.0d, 1.0d });
            //xo2.LoadParallelPolyhedronPrimitive(y => 1, h => 1, new[] { 0.0d, math.Pi / 2, math.Pi, 3 * math.Pi / 2 }, new[] { 0.0d, 1.0d });
            this.xcanvas.Begin();

            //xs = xcanvas.Children[xcanvas.Trigger.Csn];
            ////xs.InitialCamera(10);
            //this.xcanvas.Trigger.FrameRefresh += Trigger_FrameRefresh;
            ////this.xcanvas.Trigger.MouseEnterState += Trigger_MouseEnterState;
            //xo = new XObj3();
            ////xcanvas.Trigger.Rs.FillMode = Microsoft.Xna.Framework.Graphics.FillMode.WireFrame;
            //xcanvas.Trigger.Rs.CullMode = Microsoft.Xna.Framework.Graphics.CullMode.None;
            //xs.Add("aaa", xo);
            //xo.SetColor(150, 130, 80, 200);
            ////xo.effect.EnableDefaultLighting();
            ////xo.effect.PreferPerPixelLighting = true;
            ////xo.effect.LightingEnabled = true;
            ////xo.effect.Alpha = 1.0f;
            ////xo.effect.AmbientLightColor = new Vector3(10, 10, 10);
            ////xo.Present
            ////
            //xo.LoadParallelPolyhedronPrimitive(y => 1, h => 1, new[] { 0.0d, math.Pi / 2, math.Pi, 3 * math.Pi / 2 }, new[] { 0.0d, 1.0d });
            //this.xcanvas.Begin();
        }

        void Trigger_FrameRefresh(XTrigger sender) {
            //在这里 写 xo的 旋转
            //xo.World *= matrix.CreateRotationY(.03f);
            //xo.World *= matrix.CreateRotationZ(.03f);
            xo.World *= matrix.CreateRotationX(.03f);
            xo.World *= matrix.CreateRotationY(.03f);
            xo.World *= matrix.CreateRotationZ(.03f);
        }
    }
}
